#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>

using namespace std;

int convert(char *d) {
	int app[255];
	int len = strlen(d);
	char left[] = "IXCM";
	char right[] = "VLD";
	int val[255];
	val['I'] = 1;
	val['X'] = 10;
	val['C'] = 100;
	val['M'] = 1000;
	val['V'] = 5;
	val['L'] = 50;
	val['D'] = 500;

// 	//rule 1
// 	memset(app, 0, 255*sizeof(int));
// 	for (int i=0; i<len; ++i)
// 		++app[d[i]];
// 	for (int i=0; i<4; ++i) {
// 		if (app[left[i]]>3) return -1;
// 		if (app[left[i]]==3) {
// 			bool ok = false;
// 			for (int j=0; j<len-1; ++j)
// 				if (d[j]==left[i] && d[j] == d[j+1]) {
// 					ok = true;
// 					break;
// 				}
// 			if (!ok) return -1;
// 		}
// 	}
// 
// 	//rule 2
// 	for (int i=0; i<3; ++i) {
// 		if (app[right[i]] > 1) return -1;
// 	}
// 
// 
// 	// rule 0
// 	int cnt = 0;
// 	for (int i=0; i<4; ++i)
// 		cnt += app[left[i]];
// 	for (int i=0; i<3; ++i)
// 		cnt += app[right[i]];
// 	if (cnt != len) return -1;


	// rule 3
	int v = 0;
	int last = 0;
/*	int largest = 0;*/
	for (int i=len-1; i>=0; --i) {
		int thisV = val[d[i]];
		if (thisV<last) {
// 			if (thisV<largest) return -1;
			v -= thisV;
		}
		else {
			v += thisV;
		}
// 		largest = max(largest, last);
		last = thisV;
	}

	return v;
}

void doRoman(char *eq) {
// 	printf("%s\n", eq);

	char *tok1, *tok2, *tok3;
	tok1 = strtok(eq, "+");
	tok2 = strtok(NULL, "=");
	tok3 = strtok(NULL, "\n");
// 	cout << tok1 << " " << tok2 << " " << tok3 << endl;
	int x = convert(tok1);
	if (x == -1) {
		cout << "Incorrect ";
		return;
	}
	int y = convert(tok2);
	if (y == -1) {
		cout << "Incorrect ";
		return;
	}
	int z = convert(tok3);
	if (z == -1) {
		cout << "Incorrect ";
		return;
	}


// 	static bool firstblood = true;
// 	if (firstblood) firstblood = false;
// 	else cout << endl;
	
// 	printf("%d+%d=%d\n", x,y,z);

	if (x + y == z)
		cout << "Correct ";
	else
		cout << "Incorrect ";
}

vector<char> vars;
bool digUsed[10];
int varsVal[255];
int solCnt;
char *tok[3];

int convert2(char *d) {
	int v = 0;
	for (int i=0; i<strlen(d); ++i) {
		v = v*10 + varsVal[d[i]];
	}
	return v;
}

void enumAns(int x) {
	if (x == vars.size()) {
		int a = convert2(tok[0]);
		int b = convert2(tok[1]);
		int c = convert2(tok[2]);
		if (a+b == c) {
// 			cout << a << "+" << b << "=" << c << endl;
			++solCnt;
		}
		return;
	}
	int start = 0;
	for (int i=0; i<3; ++i)
		if (vars[x] == tok[i][0]) start = 1;
	for (int i=start; i<10; ++i)
		if (digUsed[i]) continue;
		else {
			digUsed[i] = true;
			varsVal[vars[x]] = i;
			enumAns(x+1);
			digUsed[i] = false;
			if (solCnt>1) return;
		}
}


void doArabic(char *eq) {
	tok[0] = strtok(eq, "+");
	tok[1] = strtok(NULL, "=");
	tok[2] = strtok(NULL, "\n");

	bool app[255];
	memset(app, 0, 255);
	for (int i=0; i<3; ++i)
		for (int j=0; j<strlen(tok[i]); ++j)
			app[tok[i][j]] = true;

	vars.clear();
	for (int i=0; i<255; ++i)
		if (app[i]) vars.push_back(i);
	solCnt = 0;
	memset(digUsed, 0, 10);
	enumAns(0);
	if (solCnt == 0) cout << "impossible";
	else if (solCnt == 1) cout << "valid";
	else cout << "ambiguous";
	cout << endl;
}

int main(void)
{
	char eq[100];
	char bakEq[100];
	while (true) {
		memset(eq, 0, 100);
		scanf(" %s", eq);
		if (eq[0] == '#') break;
		
		memcpy(bakEq, eq, 100);

		doRoman(eq);

		doArabic(bakEq);

	}
	return 0;
}